/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

/**
 *
 * @author edsonsuarez
 */
public class ExpWord {

    public static void main(String[] args) throws InvalidFormatException, IOException {
       
//        POIFSFileSystem fs = null;
        HWPFDocument doc = null;

        String nombre = "Edson Martín Emilio Juan Eduardo Rómulo Mc Kevin Suárez Aguilar";
        String nombre2 = "Martín Aguilar";
        String dni = "73193839";
        String credito = "23456543";
        String soles = "35,000";

        try {

//            fs = new POIFSFileSystem(new FileInputStream("/home/edsonsuarez/NetBeansProjects/Estandar(WF)/workflow/web/reportes/Modelo AE - Firma Titular.doc"));
            doc = new HWPFDocument(new FileInputStream("/home/edsonsuarez/NetBeansProjects/Estandar(WF)/workflow/web/reportes/Modelo AE - Firma Titular.doc"));
        
            Range range = doc.getRange();
            
                       

            //Insertar datos:
            range.replaceText(":no_usureg", "" + nombre2);
            range.replaceText(":co_docreg", "" + nombre);
            range.replaceText(":no_client", "" + nombre2);
            range.replaceText(":co_contra", "" + nombre2);
            range.replaceText(":im_presta", "" + nombre2);
            range.replaceText(":fe_diahoy", "" + nombre2);
            range.replaceText(":im_saldeu", "" + nombre2);
            range.replaceText(":ca_cuotas", "" + nombre2);
            range.replaceText(":im_cuotas", "" + nombre2);
            range.replaceText(":fe_pacini", "" + nombre2);
            range.replaceText(":fe_pacfin", "" + nombre2);
            
            for (int i = 0; i < range.numParagraphs(); i++) {
                if (range.getParagraph(i) != null) {
                    
                                        
                    Paragraph par = range.getParagraph(i);
                   
                    par.setJustification((byte) 1);
                    CharacterRun run = par.getCharacterRun(0);
                    par.setFontAlignment(i);
                    if (i == 10) {
                        run.setBold(true);
                    }

                }
            }
            
            
            XWPFDocument document = new XWPFDocument();  
            XWPFParagraph tmpParagraph = document.createParagraph();
            XWPFRun tmpRun = tmpParagraph.createRun();
            tmpRun.setText(range.text());
            tmpRun.setFontSize(10);
            document.write(new FileOutputStream(new File("/home/edsonsuarez/NetBeansPro3jects/Estandar(WF)/workflow/web/reportes/sample000123555ggg.doc")));
            
            doc.write(new FileOutputStream("/home/edsonsuarez/NetBeansProjects/Estandar(WF)/workflow/web/reportes/sample000123.doc"));
            
        } catch (Exception exep) {
            System.out.println("DENTRO DEL CATCH" + exep);
        }
    
  
    
    
    }
}
